package com.hck.taozi_help.utils.permission;

import android.content.Context;


import com.hck.taozi_help.utils.permission.domain.PermissionBuilder;
import com.hck.taozi_help.utils.permission.domain.PermissionObject;
import com.hck.taozi_help.utils.permission.interfaces.IPermissionCallback;
import com.hck.taozi_help.utils.permission.ui.PermissionActivity;

import java.util.HashMap;

public class PermissionManager {
    public static PermissionManager instance = new PermissionManager();

    public static PermissionManager getInstance() {
        return instance;
    }

    private final HashMap<String, IPermissionCallback> resultListenerHashMap = new HashMap<>();

    public IPermissionCallback getCallback(String permissionRequestId) {
        synchronized (resultListenerHashMap) {
            return resultListenerHashMap.get(permissionRequestId);
        }
    }

    public void setCallback(String requestId, IPermissionCallback resultListener) {
        synchronized (resultListenerHashMap) {
            resultListenerHashMap.put(requestId, resultListener);
        }
    }

    public void removeCallback(String requestId) {
        synchronized (resultListenerHashMap) {
            resultListenerHashMap.remove(requestId);
        }
    }

    public static void apply(Context context, PermissionObject permissionObject, IPermissionCallback resultListener) {
        PermissionActivity.apply(context, permissionObject, resultListener);
    }

    public static PermissionBuilder getBuilder(Context context){
        return new PermissionBuilder(context);
    }
}
